//
//  MusicListTableViewCell.m
//  OurRelaxDemo
//
//  Created by 王雅蓉 on 15/6/29.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "MusicListTableViewCell.h"

@interface MusicListTableViewCell ()

@property (retain, nonatomic) UIButton *colButton;
@property (retain, nonatomic) UILabel *songListLabel;
@property (retain, nonatomic) UILabel *singerListLabel;

@property (assign, nonatomic) BOOL isSelected;

@end

@implementation MusicListTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createSubviews];
        self.listMusicDetail = [[MusicForSonglist alloc] init];
        self.isSelected = YES;
    }
    
    return self;
}

-(void)createSubviews
{
    _colButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _colButton.frame = CGRectMake(5, 0, 40, 60);
    [_colButton setBackgroundImage:[UIImage imageNamed:@"musicCircleHeartDefault.png"] forState:UIControlStateNormal];
    [_colButton addTarget:self action:@selector(collectionAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_colButton];
    //[_colButton release];
    
    self.songListLabel = [[UILabel alloc] initWithFrame:CGRectMake(_colButton.frame.origin.x + _colButton.frame.size.width + 10, 5, 250, 60 / 2 - 5)];
    //_songListLabel.backgroundColor = [UIColor yellowColor];
    _songListLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:_songListLabel];
    //[_songListLabel release];
    
    self.singerListLabel = [[UILabel alloc] initWithFrame:CGRectMake(_songListLabel.frame.origin.x, _songListLabel.frame.origin.y + _songListLabel.frame.size.height + 2, _songListLabel.frame.size.width, _songListLabel.frame.size.height / 2 + 5)];
    //_singerListLabel.backgroundColor = [UIColor redColor];
    _singerListLabel.font = [UIFont systemFontOfSize:14.0];
    _singerListLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_singerListLabel];
    [_singerListLabel release];
}

-(void)collectionAction:(UIButton *)button
{
    if (_isSelected) {
        
        _isSelected = NO;
        [_colButton setBackgroundImage:[UIImage imageNamed:@"musicCircleHeartSelected.png"] forState:UIControlStateNormal];
    } else {
        
        _isSelected = YES;
        [_colButton setBackgroundImage:[UIImage imageNamed:@"musicCircleHeartDefault.png"] forState:UIControlStateNormal];
    }
}

-(void)setListMusicDetail:(MusicForSonglist *)listMusicDetail
{
    if (_listMusicDetail != listMusicDetail) {
        
        [_listMusicDetail release];
        _listMusicDetail = [listMusicDetail retain];
    }
    //NSLog(@"%@",listMusicDetail.song_name);
    _songListLabel.text = listMusicDetail.song_name;
    _singerListLabel.text = listMusicDetail.singer_name;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
